#include <iostream>
#include <vector>
using namespace std;

class App {
	int cnt;
	int edges, vertex;
	vector<int> head, next, to;

	int best, center;
	vector<int> size;

	void dfs(int u, int p)
	{
		size[u] = 1;
		int maxsub = 0;
		for (int e = head[u], v = 0; e; e = next[e]) {
			v = to[e];
			if (v != p) {
				dfs(v, u);
				size[u] += size[v];
				maxsub = max(maxsub, size[v]);
			}
		}
		maxsub = max(maxsub, vertex - size[u]);
		if (maxsub < best || (maxsub == best && u < center)) {
			best = maxsub;
			center = u;
		}
	}

    public:
	App(int n) : vertex(n), edges((n << 1) + 1), head(n + 1, 0), next(edges, 0), to(edges, 0), size(n + 1, 0)
	{
		cnt = 1;
		best = 2147483647;
		center = -1;
	}

	void addedge(int u, int v)
	{
		next[cnt] = head[u];
		to[cnt] = v;
		head[u] = cnt++;
	}

	void balance()
	{
		dfs(1, 0);
	}

	int getcenter()
	{
		return center;
	}

	int getblance()
	{
		return best;
	}
};

int main()
{
	int t = 0;
	cin >> t;
	for (int i = 1; i <= t; i++) {
		int n = 0;
		cin >> n;
		App app(n);
		for (int j = 0, u, v; j < n - 1; j++) {
			cin >> u >> v;
			app.addedge(u, v);
			app.addedge(v, u);
		}
                app.balance();
		cout << app.getcenter() << " " << app.getblance() << '\n';
	}
	return 0;
}